﻿using System;
using System.Collections.Generic;
using System.Linq;


namespace upres
{
    class LibFunction
    {
        /// <summary>
        /// return the string
        /// </summary>
        /// <param name="time">04:02:20</param>
        public static String countDown(String time)
        {
            String result = "";
            String[] temp = time.Split(':');
            int hours = Convert.ToByte(temp[0]);
            int minutes = Convert.ToByte(temp[1]);
            int seconds = Convert.ToByte(temp[2]);
            if (hours == 0 && minutes == 0 && seconds == 0)
            {
                return "00:00:00";
            }
            if (hours > 0)
            {
                if (minutes > 0)
                {
                    if (seconds > 0)
                    {
                        seconds--;
                    }
                    else
                    {
                        seconds = 59;
                        minutes--;
                    }
                }
                else
                {
                    minutes = 59;
                    hours--;
                }


            }
            else
            {
                if (hours == 0)
                {
                    if (minutes > 0)
                    {
                        if (seconds > 0)
                        {
                            seconds--;
                        }
                        else
                        {
                            seconds = 59;
                            minutes--;
                        }
                    }
                    else
                    {
                        seconds--;
                    }

                }
            }            
            if (hours.ToString().Length == 1)
            {
                result += "0" + hours.ToString();
            }
            else
            {
                result += hours.ToString();
            }
            if ((minutes.ToString().Length) == 1)
                result += ":0" + minutes.ToString();
            else
            {
                result += ":" + minutes.ToString();
            }

            if ((seconds.ToString().Length) == 1)
                result += ":0" + seconds.ToString();
            else
            {
                result += ":" + seconds.ToString();
            }
            return result;
        }

    }
}
